{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a8b892c8",
   "metadata": {},
   "source": [
    "Printed and electronic copies of *Modeling and Simulation in Python* are available from [No Starch Press](https://nostarch.com/modeling-and-simulation-python) and [Bookshop.org](https://bookshop.org/p/books/modeling-and-simulation-in-python-allen-b-downey/17836697?ean=9781718502161) and [Amazon](https://amzn.to/3y9UxNb)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "existing-guidance",
   "metadata": {},
   "source": [
    "# Sweeping Parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "imported-table",
   "metadata": {
    "tags": []
   },
   "source": [
    "*Modeling and Simulation in Python*\n",
    "\n",
    "Copyright 2021 Allen Downey\n",
    "\n",
    "License: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "electoral-turkey",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# install Pint if necessary\n",
    "\n",
    "try:\n",
    "    import pint\n",
    "except ImportError:\n",
    "    !pip install pint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "formal-context",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# download modsim.py if necessary\n",
    "\n",
    "from os.path import basename, exists\n",
    "\n",
    "def download(url):\n",
    "    filename = basename(url)\n",
    "    if not exists(filename):\n",
    "        from urllib.request import urlretrieve\n",
    "        local, _ = urlretrieve(url, filename)\n",
    "        print('Downloaded ' + local)\n",
    "    \n",
    "download('https://raw.githubusercontent.com/AllenDowney/' +\n",
    "         'ModSimPy/master/modsim.py')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "progressive-typing",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# import functions from modsim\n",
    "\n",
    "from modsim import *"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "caring-gnome",
   "metadata": {
    "tags": []
   },
   "source": [
    "The following cells download the code from Chapter 3 and import the `step` function we defined."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ranking-today",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "download('https://raw.githubusercontent.com/AllenDowney/' +\n",
    "         'ModSimPy/master/chap03.py')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "stylish-raising",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from chap03 import step"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "atlantic-collectible",
   "metadata": {},
   "source": [
    "In the previous chapter we defined metrics that quantify the performance of a bike sharing system.\n",
    "In this chapter we'll see how those metrics depend on the parameters of the system, like the arrival rate of customers at the stations.\n",
    "\n",
    "And I will present a program development strategy, called incremental\n",
    "development, that might help you write programs faster and spend less\n",
    "time debugging."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "plastic-trigger",
   "metadata": {},
   "source": [
    "This chapter is available as a Jupyter notebook where you can read the text, run the code, and work on the exercises. \n",
    "Click here to access the notebooks: <https://allendowney.github.io/ModSimPy/>."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "strategic-newspaper",
   "metadata": {},
   "source": [
    "## Functions That Return Values\n",
    "\n",
    "We have used several functions that return values.\n",
    "For example, when you run `sqrt`, it returns a number you can assign to a variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "imposed-pregnancy",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import sqrt\n",
    "\n",
    "root_2 = sqrt(2)\n",
    "root_2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "unsigned-recipe",
   "metadata": {},
   "source": [
    "And when you run `State`, it returns a new `State` object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "accessible-wallace",
   "metadata": {},
   "outputs": [],
   "source": [
    "bikeshare = State(olin=10, wellesley=2)\n",
    "bikeshare"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "missing-pendant",
   "metadata": {},
   "source": [
    "Not all functions have return values. For example, when you run `step`,\n",
    "it updates a `State` object, but it doesn't return a value.\n",
    "\n",
    "To write functions that return values, we can use a `return` statement, like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "minimal-supervisor",
   "metadata": {},
   "outputs": [],
   "source": [
    "def add_five(x):\n",
    "    return x + 5"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "sized-intensity",
   "metadata": {},
   "source": [
    "`add_five` takes a parameter, `x`, which could be any number. It\n",
    "computes `x + 5` and returns the result. So if we run it like this, the\n",
    "result is `8`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "warming-program",
   "metadata": {},
   "outputs": [],
   "source": [
    "add_five(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "rental-representation",
   "metadata": {},
   "source": [
    "As a more useful example, here's a version of `run_simulation` that\n",
    "creates a `State` object, runs a simulation, and then returns the\n",
    "`State` object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "sitting-cleveland",
   "metadata": {},
   "outputs": [],
   "source": [
    "def run_simulation(p1, p2, num_steps):\n",
    "    state = State(olin=10, wellesley=2,\n",
    "                  olin_empty=0, wellesley_empty=0)\n",
    "    \n",
    "    for i in range(num_steps):\n",
    "        step(state, p1, p2)\n",
    "        \n",
    "    return state"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "minimal-ability",
   "metadata": {},
   "source": [
    "We can call `run_simulation` like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "difficult-shepherd",
   "metadata": {},
   "outputs": [],
   "source": [
    "final_state = run_simulation(0.3, 0.2, 60)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "charming-wheel",
   "metadata": {},
   "source": [
    "The result is a `State` object that represents the final state of the system, including the metrics we'll use to evaluate the performance of the system:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "tough-sweet",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(final_state.olin_empty, \n",
    "      final_state.wellesley_empty)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aggregate-lightweight",
   "metadata": {},
   "source": [
    "The simulation we just ran starts with `olin=10` and `wellesley=2`, and uses the values `p1=0.3`, `p2=0.2`, and `num_steps=60`. \n",
    "These five values are *parameters of the model*, which are quantities that determine the behavior of the system.\n",
    "\n",
    "It is easy to get the parameters of a model confused with the parameters of a function. \n",
    "It is especially easy because the parameters of a model often appear as parameters of a function.\n",
    "\n",
    "For example, the previous version of `run_simulation` takes `p1`, `p2`, and `num_steps` as parameters.\n",
    "So we can call `run_simulation` with different parameters and see how\n",
    "the metrics, like the number of unhappy customers, depend on the\n",
    "parameters. But before we do that, we need a new version of a `for` loop."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "valuable-aircraft",
   "metadata": {},
   "source": [
    "## Loops and Arrays\n",
    "\n",
    "In `run_simulation`, we use this `for` loop:\n",
    "\n",
    "```\n",
    "    for i in range(num_steps):\n",
    "        step(state, p1, p2)\n",
    "```\n",
    "\n",
    "In this example, `range` creates a sequence of numbers from `0` to `num_steps` (including `0` but not `num_steps`). \n",
    "Each time through the loop, the next number in the sequence gets assigned to the loop variable, `i`.\n",
    "\n",
    "But `range` only works with integers; to get a sequence of non-integer\n",
    "values, we can use `linspace`, which is provided by NumPy:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "bound-juice",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import linspace\n",
    "\n",
    "p1_array = linspace(0, 1, 5)\n",
    "p1_array"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ordered-colleague",
   "metadata": {},
   "source": [
    "The arguments indicate where the sequence should start and stop, and how\n",
    "many elements it should contain. In this example, the sequence contains\n",
    "`5` equally-spaced numbers, starting at `0` and ending at `1`.\n",
    "\n",
    "The result is a NumPy *array*, which is a new kind of object we have\n",
    "not seen before. An array is a container for a sequence of numbers.\n",
    "\n",
    "We can use an array in a `for` loop like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "commercial-methodology",
   "metadata": {},
   "outputs": [],
   "source": [
    "for p1 in p1_array:\n",
    "    print(p1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "finnish-budapest",
   "metadata": {},
   "source": [
    "When this loop runs, it\n",
    "\n",
    "1.  Gets the first value from the array and assigns it to `p1`.\n",
    "\n",
    "2.  Runs the body of the loop, which prints `p1`.\n",
    "\n",
    "3.  Gets the next value from the array and assigns it to `p1`.\n",
    "\n",
    "4.  Runs the body of the loop, which prints `p1`.\n",
    "\n",
    "5. ...\n",
    "\n",
    "And so on, until it gets to the end of the array. This will come in handy in the next section."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "crazy-belize",
   "metadata": {},
   "source": [
    "## Sweeping Parameters\n",
    "\n",
    "If we know the actual values of parameters like `p1` and `p2`, we can\n",
    "use them to make specific predictions, like how many bikes will be at\n",
    "Olin after one hour.\n",
    "\n",
    "But prediction is not the only goal; models like this are also used to\n",
    "explain why systems behave as they do and to evaluate alternative\n",
    "designs. For example, if we observe the system and notice that we often run out of bikes at a particular time, we could use the model to figure out why that happens. And if we are considering adding more bikes, or another station, we could evaluate the effect of various \"what if\" scenarios.\n",
    "\n",
    "As an example, suppose we have enough data to estimate that `p2` is\n",
    "about `0.2`, but we don't have any information about `p1`. We could run simulations with a range of values for `p1` and see how the results vary. This process is called *sweeping* a parameter, in the sense that the value of the parameter \"sweeps\" through a range of possible values.\n",
    "\n",
    "Now that we know about loops and arrays, we can use them like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "working-chair",
   "metadata": {},
   "outputs": [],
   "source": [
    "p1_array = linspace(0, 0.6, 6)\n",
    "p2 = 0.2\n",
    "num_steps = 60\n",
    "\n",
    "for p1 in p1_array:\n",
    "    final_state = run_simulation(p1, p2, num_steps)\n",
    "    print(p1, final_state.olin_empty)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "chicken-mainstream",
   "metadata": {},
   "source": [
    "Each time through the loop, we run a simulation with a different value\n",
    "of `p1` and the same value of `p2`, `0.2`. Then we print `p1` and the\n",
    "number of unhappy customers at Olin.\n",
    "\n",
    "To save and plot the results, we can use a `SweepSeries` object, which\n",
    "is similar to a `TimeSeries`; the difference is that the labels in a\n",
    "`SweepSeries` are parameter values rather than time values.\n",
    "\n",
    "We can create an empty `SweepSeries` like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "instrumental-session",
   "metadata": {},
   "outputs": [],
   "source": [
    "sweep = SweepSeries()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "listed-orleans",
   "metadata": {},
   "source": [
    "And add values like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "hollywood-technical",
   "metadata": {},
   "outputs": [],
   "source": [
    "p1_array = linspace(0, 0.6, 31)\n",
    "\n",
    "for p1 in p1_array:\n",
    "    final_state = run_simulation(p1, p2, num_steps)\n",
    "    sweep[p1] = final_state.olin_empty"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "healthy-prime",
   "metadata": {},
   "source": [
    "The result is a `SweepSeries` that maps from each value of `p1` to the\n",
    "resulting number of unhappy customers."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "driven-theme",
   "metadata": {
    "tags": []
   },
   "source": [
    "We can display the results like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "recovered-buffalo",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "show(sweep)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "instructional-showcase",
   "metadata": {},
   "source": [
    "We can plot the elements of the `SweepSeries` like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "hollywood-spirit",
   "metadata": {},
   "outputs": [],
   "source": [
    "sweep.plot(label='Olin', color='C1')\n",
    "\n",
    "decorate(title='Olin-Wellesley bikeshare',\n",
    "         xlabel='Customer rate at Olin (p1 in customers/min)', \n",
    "         ylabel='Number of unhappy customers at Olin')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "educated-bloom",
   "metadata": {},
   "source": [
    "The keyword argument `color='C1'` specifies the color of the line.\n",
    "The `TimeSeries` we have plotted so far use the default color, `C0`, which is blue (see <https://matplotlib.org/stable/tutorials/colors/colors.html> for the other colors defined by Matplotlib).\n",
    "I use a different color for `SweepSeries` to remind us that it is not a `TimeSeries`.\n",
    "\n",
    "When the arrival rate at Olin is low, there are plenty of bikes and no unhappy customers.\n",
    "As the arrival rate increases, we are more likely to run out of bikes and the number of unhappy customers increases. The line is jagged because the simulation is based on random numbers. Sometimes we get lucky and there are relatively few unhappy customers; other times we are unlucky and there are more. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "korean-christianity",
   "metadata": {},
   "source": [
    "## Incremental Development\n",
    "\n",
    "When you start writing programs that are more than a few lines, you\n",
    "might find yourself spending more time debugging. The more code you write before you start debugging, the harder it is to find the problem.\n",
    "\n",
    "*Incremental development* is a way of programming that tries to\n",
    "minimize the pain of debugging. The fundamental steps are:\n",
    "\n",
    "1.  Always start with a working program. If you have an example from a\n",
    "    book, or a program you wrote that is similar to what you are working\n",
    "    on, start with that. Otherwise, start with something you *know* is\n",
    "    correct, like `x=5`. Run the program and confirm that it does what\n",
    "    you expect.\n",
    "\n",
    "2.  Make one small, testable change at a time. A \"testable\" change is\n",
    "    one that displays something or has some other effect you can check.\n",
    "    Ideally, you should know what the correct answer is, or be able to\n",
    "    check it by performing another computation.\n",
    "\n",
    "3.  Run the program and see if the change worked. If so, go back to\n",
    "    Step 2. If not, you have to do some debugging, but if the\n",
    "    change you made was small, it shouldn't take long to find the\n",
    "    problem.\n",
    "\n",
    "When this process works, your changes usually work the first time or, if they don't, the problem is obvious. In practice, there are two problems with incremental development:\n",
    "\n",
    "-   Sometimes you have to write extra code to generate visible output\n",
    "    that you can check. This extra code is called *scaffolding*\n",
    "    because you use it to build the program and then remove it when you\n",
    "    are done. That might seem like a waste, but time you spend on\n",
    "    scaffolding is almost always time you save on debugging.\n",
    "\n",
    "-   When you are getting started, it might not be obvious how to choose\n",
    "    the steps that get from `x=5` to the program you are trying to\n",
    "    write. You will see more examples of this process as we go along,\n",
    "    and you will get better with experience.\n",
    "\n",
    "If you find yourself writing more than a few lines of code before you\n",
    "start testing, and you are spending a lot of time debugging, try\n",
    "incremental development."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "nominated-assault",
   "metadata": {},
   "source": [
    "## Summary\n",
    "\n",
    "This chapter introduces functions that return values, which we use to write a version of `run_simulation` that returns a `State` object with the final state of the system.\n",
    "\n",
    "It also introduces `linspace`, which we use to create a NumPy array, and `SweepSeries`, which we use to store the results of a parameter sweep.\n",
    "\n",
    "We used a parameter sweep to explore the relationship between one of the parameters, `p1`, and the number of unhappy customers, which is a metric that quantifies how well (or badly) the system works.\n",
    "\n",
    "In the exercises, you'll have a chance to sweep other parameters and compute other metrics.\n",
    "\n",
    "In the next chapter, we'll move on to a new problem, modeling and predicting world population growth."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "appreciated-preview",
   "metadata": {},
   "source": [
    "## Exercises"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "primary-quest",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "\n",
    " Write a function called `make_state` that creates a `State` object with the state variables `olin=10` and `wellesley=2`, and then returns the new `State` object.\n",
    "\n",
    "Write a line of code that calls `make_state` and assigns the result to a variable named `init`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "reflected-freedom",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "north-formation",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "robust-blair",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "\n",
    "Read the documentation of `linspace` at <https://numpy.org/doc/stable/reference/generated/numpy.linspace.html>. Then use it to make an array of 101 equally spaced points between 0 and 1 (including both)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "collected-butter",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fleet-debut",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "\n",
    " Wrap the code from this chapter in a function named `sweep_p1` that takes an array called `p1_array` as a parameter.  It should create a new `SweepSeries` and run a simulation for each value of `p1` in `p1_array`, with `p2=0.2` and `num_steps=60`.\n",
    "It should store the results in the `SweepSeries` and return it.  \n",
    "\n",
    "Use your function to generate a `SweepSeries` and then plot the number of unhappy customers at Olin as a function of `p1`.  Label the axes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "authorized-sarah",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "romance-wisdom",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "developmental-broad",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "\n",
    " Write a function called `sweep_p2` that runs simulations with `p1=0.5` and a range of values for `p2`.  It should store the results in a `SweepSeries` and return the `SweepSeries`.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "norman-banana",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "mexican-robert",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "separate-mention",
   "metadata": {},
   "source": [
    "## Challenge Exercises\n",
    "\n",
    "The following two exercises are a little more challenging.  If you are comfortable with what you have learned so far, you should give them a try.  If you feel like you have your hands full, you might want to skip them for now."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bearing-orbit",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "\n",
    " Because our simulations are random, the results vary from one run to another, and the results of a parameter sweep tend to be noisy.  We can get a clearer picture of the relationship between a parameter and a metric by running multiple simulations with the same parameter and taking the average of the results.\n",
    "\n",
    "Write a function called `run_multiple_simulations` that takes as parameters `p1`, `p2`, `num_steps`, and `num_runs`.\n",
    "`num_runs` specifies how many times it should call `run_simulation`.\n",
    "\n",
    "After each run, it should store the total number of unhappy customers (at Olin or Wellesley) in a `TimeSeries`.\n",
    "At the end, it should return the `TimeSeries`.\n",
    "\n",
    "Test your function with parameters\n",
    "\n",
    "```\n",
    "p1 = 0.3\n",
    "p2 = 0.3\n",
    "num_steps = 60\n",
    "num_runs = 10\n",
    "```\n",
    "\n",
    "Display the resulting `TimeSeries` and use the `mean` function from NumPy to compute the average number of unhappy customers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "accredited-salmon",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "visible-allowance",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "spatial-fundamentals",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "structural-expense",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "\n",
    "Continuing the previous exercise, use `run_multiple_simulations` to run simulations with a range of values for `p1` and `p2`.\n",
    "\n",
    "```\n",
    "p2 = 0.3\n",
    "num_steps = 60\n",
    "num_runs = 20\n",
    "```\n",
    "\n",
    "Store the results in a `SweepSeries`, then plot the average number of unhappy customers as a function of `p1`.  Label the axes.\n",
    "\n",
    "What value of `p1` minimizes the average number of unhappy customers?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "reverse-emphasis",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "broad-latitude",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "biblical-federal",
   "metadata": {},
   "source": [
    "## Under the Hood\n",
    "\n",
    "The object you get when you call `SweepSeries` is actually a Pandas `Series`, the same as the object you get from `TimeSeries`.\n",
    "I give them different names to help us remember that they play different roles.\n",
    "\n",
    "`Series` provides a number of functions, which you can read about at <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html>.\n",
    "\n",
    "They include `mean`, which computes the average of the values in the `Series`, so if you have a `Series` named `totals`, for example, you can compute the mean like this:\n",
    "\n",
    "```\n",
    "    totals.mean()\n",
    "```\n",
    "\n",
    "`Series` provides other statistical functions, like `std`, which computes the standard deviation of the values in the series.\n",
    "\n",
    "In this chapter I use the keyword argument `color` to specify the color of a line plot.\n",
    "You can read about the other available colors at <https://matplotlib.org/3.3.2/tutorials/colors/colors.html>."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "federal-cemetery",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
